namespace OasisCiq.Xnl
{
    // TODO: XLink attributes
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Xml;
    using System.Xml.Schema;
    using System.Xml.Serialization;
    using CommonTypes;
    using External;
    using Xml;
    using XS;

    /// <summary>
    /// Reusable complex type
    /// </summary>
    public class OrganisationNameType :
        IDataQualityGroup, 
        IValidityDateGroup, 
        ILanguageCodeGroup, 
        IXLink, 
        IExtendedAttributes, 
        IXmlSerializable
    {
        private static readonly XmlQualifiedName XmlElementName =
            new XmlQualifiedName("OrganisationName", XmlNamespaces.Name);

        public virtual ICollection<OrganisationNameElement> NameElements { get; set; }

        public virtual ICollection<SubDivisionName> SubDivisions { get; set; }

        /// <summary>
        /// Enumerated list of common types of aliases or name types.
        /// </summary>
        public virtual OrganisationNameTypeList Type { get; set; }

        /// <summary>
        /// A unique identifier of an organisation
        /// </summary>
        public virtual CTString OrganisationId { get; set; }

        /// <summary>
        /// Type of identifier
        /// </summary>
        public virtual OrganisationIdTypeList OrganisationIdType { get; set; }

        /// <summary>
        /// Globally unique identifer
        /// </summary>
        public virtual CTString Id { get; set; }

        /// <summary>
        /// Usage of organisation name. How is it used and for what purpose.
        /// Allows user which name in a set of names to select for a given purpose.
        /// e.g. used for legal purposes
        /// </summary>
        public virtual OrganisationNameUsageList Usage { get; set; }

        /// <summary>
        /// Status of the entity. e.g. Old, Current, Inactive, Active, etc
        /// </summary>
        public virtual StatusList Status { get; set; }

        public virtual XSDateTime DateValidFrom { get; set; }

        public virtual XSDateTime DateValidTo { get; set; }

        public virtual NameKeyGroup NameKey { get; set; }

        public virtual DataQualityTypeList DataQualityType { get; set; }

        public virtual XSDateTime ValidFrom { get; set; }

        public virtual XSDateTime ValidTo { get; set; }

        public virtual XSLanguage LanguageCode { get; set; }

        public virtual NameValueCollection ExtendedAttributes { get; set; }

        #region IXmlSerializable implementation

        XmlSchema IXmlSerializable.GetSchema()
        {
            return null;
        }

        public virtual void ReadXml(XmlReader reader)
        {
            var wrapper = XmlUtilities.Wrap(reader);
            if (XmlUtilities.MoveToElement(wrapper, XmlElementName))
            {
                new XnlXmlReader(wrapper).ReadOrganisationName(
                    this,
                    XmlElementName.Name,
                    XmlElementName.Namespace);
            }
        }

        public virtual void WriteXml(XmlWriter writer)
        {
            new XnlXmlWriter(writer).WriteOrganisationName(this);
        }

        #endregion
    }
}